package org.alex.samples.dao;

import java.util.List;

import org.alex.samples.model.ExamUserSubject;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
@Transactional
public class ExamUserSubjectDAOImp extends BaseHibernateDAO<ExamUserSubject> implements IExamUserSubjectDAO{

	@Override
	public List<ExamUserSubject> findAllExamUserSubject() {
		List<ExamUserSubject> list = this.find("FROM ExamUserSubject");
		return list;
	}

	@Override
	public List<ExamUserSubject> getSubjectByUserId(String userId) {
		List<ExamUserSubject> exsitsUser = this.queryForList(" FROM ExamUserSubject AS s WHERE s.userJDBC.userId=? ", new Object[]{userId});
		if (exsitsUser != null) {
			return exsitsUser;
		}else{
			return null;
		}
	}

	@Override
	public void delExamUserSubjectBySubId(Integer subId) {
		String sql = " DELETE FROM exam_user_subject WHERE exam_user_subject.sub_id = :subId ";
		this.createSqlQuery(sql).setInteger("subId", subId).executeUpdate();
	}

	
}
